package com.lucy.auth.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.URLUtil;
import com.lucy.common.domain.ResponseDTO;
import com.lucy.common.redis.RedisCache;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 请求转发控制器
 */
@ApiIgnore
@Controller
@RequestMapping("sso")
@Api(tags = "系统转发")
public class ForwardController {
    @Autowired
    RedisCache redisCache;

    @GetMapping("forward")
    @ApiOperation(value = "请求转发")
    public void forwardSubSys(@RequestParam("backUrl") String backUrl, HttpServletResponse response) throws IOException {
        //response.sendRedirect("/disk/default/preview/"+documentKey);
        // 1. 获取登录用户 TOKEN
        String token = StpUtil.getTokenValue();
        // 2. 生成 ticket
        String simpleId = IdUtil.fastSimpleUUID();
        // 3. 配置缓存
        redisCache.setCacheObject(simpleId,token);
        // 4. 跳转
        response.sendRedirect(backUrl+"?ticket="+simpleId);
    }

    @GetMapping("login")
    @ApiOperation(value = "登录")
    public ModelAndView ssoLogin(){
        return null;
    }

}
